package com.aiyun.rabbit.rabbitdemo.order.service;


import java.io.IOException;
import java.nio.charset.StandardCharsets;

import com.aiyun.rabbit.rabbitdemo.dto.OrderDTO;
import com.aiyun.rabbit.rabbitdemo.dto.OrderStatus;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import static org.slf4j.LoggerFactory.getLogger;

@Service
@Slf4j
public class OrderService {


	@RabbitListener(queues = "queue.order.confirm")
	public void listenOrderConfirm(String message) throws IOException {
		OrderDTO orderDTO = new ObjectMapper().readValue(message.getBytes(StandardCharsets.UTF_8), OrderDTO.class);
		orderDTO.setOrderStatus(OrderStatus.FINISHED);
		log.info("订单状态已经确认，订单信息是:[{}]", orderDTO);
	}

	@RabbitListener(queues = "queue.order.process.failure")
	public void orderFailureProcess(String message){
		log.error("订单服务收到订单失败信息，该订单是：[{}]", message);
	}


	@RabbitListener(queues = "queue.order.check")
	public void orderCheck(String message){
		log.info("执行订单支付检查，订单信息是:[{}]", message);
	}
}
